package com.jason.kotlin

import android.app.Application
import android.content.Context
import com.jason.library.common.JasonTools
import com.jason.library.crash.CrashListener
import com.jason.library.crash.CrashManager
import com.jason.library.crash.CrashUtils
import com.jason.library.network.utils.NetworkTool

class MyApp : Application() {

    override fun onCreate() {
        super.onCreate()

        CrashManager.getInstance().setCrashLocal()
        CrashManager.getInstance().init(
            this,
            object : CrashListener {

                override fun againStartApp() {
                    //通过开启服务延迟app重启
                    //CrashUtils.restartAppWithDelay(this@MyApp, 2000)
                    //指定app重启 延迟多久重启，并且重启后，打开某个页面
                    CrashUtils.restartAppFromTargetActivity(this@MyApp, 2000, MainActivity::class.java)
                    //直接重启App
                    //CrashUtils.restartAppFromCurrentActivity(this@MyApp)
                }

                override fun recordException(ex: Throwable?) {
                    // TODO: 2020/11/20 这边可以做其他的异常相关的处理操作
                }

            }
        )

        JasonTools.getInstance().init(this)
        JasonTools.getInstance().setFloat(this)

    }

    init {
        mContext = this
    }

    companion object {
        lateinit var mContext: Context
        fun getContext() = mContext
    }
}